using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The UserAccountTypeCodeTableManager class is responsible for managing BO.UserAccountTypeCodeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class UserAccountTypeCodeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all UserAccountTypeCodeTable objects in the database.
        /// </summary>
        /// <returns>A list with all UserAccountTypeCodeTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static UserAccountTypeCodeTableList GetList()
        {
            return UserAccountTypeCodeTableDB.GetList();
        }

        /// <summary>
        /// Gets a single UserAccountTypeCodeTable from the database without its data.
        /// </summary>
        /// <param name="userAccountTypeCode">The UserAccountTypeCode of the UserAccountTypeCodeTable in the database.</param>
        /// <returns>A UserAccountTypeCodeTable object when the UserAccountTypeCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static UserAccountTypeCodeTable GetItem(short userAccountTypeCode)
        {
            return GetItem(userAccountTypeCode, false);
        }

        /// <summary>
        /// Gets a single UserAccountTypeCodeTable from the database.
        /// </summary>
        /// <param name="userAccountTypeCode">The UserAccountTypeCode of the UserAccountTypeCodeTable in the database.</param>
        /// <param name="getUserAccountTypeCodeTableRecords">Determines whether to load all associated UserAccountTypeCodeTable records as well.</param>
        /// <returns>
        /// A UserAccountTypeCodeTable object when the UserAccountTypeCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static UserAccountTypeCodeTable GetItem(short userAccountTypeCode, bool getUserAccountTypeCodeTableRecords)
        {
            UserAccountTypeCodeTable myUserAccountTypeCodeTable = UserAccountTypeCodeTableDB.GetItem(userAccountTypeCode);
            //if (myUserAccountTypeCodeTable != null && getUserAccountTypeCodeTableRecords)
            //{
            //    myUserAccountTypeCodeTable.userAccountTables = UserAccountTableDB.GetListByUserAccountTypeCode(userAccountTypeCode);
            //}
            return myUserAccountTypeCodeTable;
        }

        /// <summary>
        /// Saves a UserAccountTypeCodeTable in the database.
        /// </summary>
        /// <param name="myUserAccountTypeCodeTable">The UserAccountTypeCodeTable instance to save.</param>
        /// <returns>The new UserAccountTypeCode if the UserAccountTypeCodeTable is new in the database or the existing UserAccountTypeCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(UserAccountTypeCodeTable myUserAccountTypeCodeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short userAccountTypeCodeTableUserAccountTypeCode = UserAccountTypeCodeTableDB.Save(myUserAccountTypeCodeTable);
                //foreach (UserAccountTable myUserAccountTable in myUserAccountTypeCodeTable.userAccountTables)
                //{
                //    myUserAccountTable.UserAccountTypeCode = userAccountTypeCodeTableUserAccountTypeCode;
                //    UserAccountTableDB.Save(myUserAccountTable);
                //}

                //  Assign the UserAccountTypeCodeTable its new (or existing UserAccountTypeCode).
                myUserAccountTypeCodeTable.UserAccountTypeCode = userAccountTypeCodeTableUserAccountTypeCode;

                myTransactionScope.Complete();

                return userAccountTypeCodeTableUserAccountTypeCode;
            }
        }

        /// <summary>
        /// Deletes a UserAccountTypeCodeTable from the database.
        /// </summary>
        /// <param name="myUserAccountTypeCodeTable">The UserAccountTypeCodeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(UserAccountTypeCodeTable myUserAccountTypeCodeTable)
        {
            return UserAccountTypeCodeTableDB.Delete(myUserAccountTypeCodeTable.UserAccountTypeCode);
        }

        #endregion

    }

}
